package com.xuexiang.xui_lib.component.textview.supertextview;

import ohos.agp.components.AttrHelper;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.components.element.Element;
import ohos.agp.text.Font;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextAlignment;
import ohos.app.Context;

import com.xuexiang.xui_lib.ResourceTable;
import com.xuexiang.xui_lib.component.textview.supertextview.adapter.HasTypeface;
import com.xuexiang.xui_lib.component.textview.supertextview.adapter.OfText;
import com.xuexiang.xui_lib.util.AttrValue;
import com.xuexiang.xui_lib.util.ColorUtils;
import com.xuexiang.xui_lib.util.DisplayUtils;

import static ohos.agp.components.DependentLayout.LayoutConfig.ABOVE;
import static ohos.agp.components.DependentLayout.LayoutConfig.ALIGN_PARENT_BOTTOM;
import static ohos.agp.components.DependentLayout.LayoutConfig.ALIGN_PARENT_LEFT;
import static ohos.agp.components.DependentLayout.LayoutConfig.ALIGN_PARENT_RIGHT;
import static ohos.agp.components.DependentLayout.LayoutConfig.ALIGN_PARENT_TOP;
import static ohos.agp.components.DependentLayout.LayoutConfig.BELOW;
import static ohos.agp.components.DependentLayout.LayoutConfig.CENTER_IN_PARENT;
import static ohos.agp.components.DependentLayout.LayoutConfig.LEFT_OF;
import static ohos.agp.components.DependentLayout.LayoutConfig.RIGHT_OF;
import static ohos.agp.components.DependentLayout.LayoutConfig.TRUE;
import static ohos.agp.components.DependentLayout.LayoutConfig.VERTICAL_CENTER;

/**
 * 通用的textView可以实现大部分常用布局样式
 *
 * @since 2021-04-07
 */
public class CommonTextView extends DependentLayout implements HasTypeface {
    private Context mContext;

    private Color mDefaultTextColor;//文字默认颜色
    private int mDefaultTextSize;//默认字体大小
    private int mDefaultPadding;//默认边距

    private Color mBackgroundColor = Color.TRANSPARENT;//背景颜色

    private Element mLeft_ElementLeft;
    private Element mLeft_ElementTop;
    private Element mLeft_ElementRight;
    private Element mLeft_ElementBottom;

    private Element mCenter_ElementLeft;
    private Element mCenter_ElementTop;
    private Element mCenter_ElementRight;
    private Element mCenter_ElementBottom;

    private Element mRight_ElementLeft;
    private Element mRight_ElementTop;
    private Element mRight_ElementRight;
    private Element mRight_ElementBottom;

    private Element mLeft_IV_Element;

    private String mLeftTextString;
    private String mLeftTopTextString;
    private String mLeftBottomTextString;

    private String mRightTextString;
    private String mRightTopTextString;
    private String mRightBottomTextString;

    private String mCenterTextString;
    private String mCenterTopTextString;
    private String mCenterBottomTextString;

    private int mLeftTextSize;
    private int mLeftTopTextSize;
    private int mLeftBottomTextSize;

    private int mRightTextSize;
    private int mRightTopTextSize;
    private int mRightBottomTextSize;

    private int mCenterTextSize;
    private int mCenterTopTextSize;
    private int mCenterBottomTextSize;

    private Color mLeftTextColor;
    private Color mLeftTopTextColor;
    private Color mLeftBottomTextColor;

    private Color mCenterTextColor;
    private Color mCenterTopTextColor;
    private Color mCenterBottomTextColor;

    private Color mRightTextColor;
    private Color mRightTopTextColor;
    private Color mRightBottomTextColor;

    private int mLeftIconElementPadding;
    private int mCenterIconElementPadding;
    private int mRightIconElementPadding;

    private int mLeftViewPaddingLeft;
    private int mLeftViewPaddingRight;

    private int mCenterViewPaddingLeft;
    private int mCenterViewPaddingRight;

    private int mRightViewPaddingLeft;
    private int mRightViewPaddingRight;

    private int mTopDividerLineMarginLR;
    private int mTopDividerLineMarginLeft;
    private int mTopDividerLineMarginRight;

    private int mBottomDividerLineMarginLR;
    private int mBottomDividerLineMarginLeft;
    private int mBottomDividerLineMarginRight;

    private int mBothDividerLineMarginLeft;
    private int mBothDividerLineMarginRight;

    private int mCenterSpaceHeight;

    private int mLeftImageViewMarginLeft;
//    private int mRightImageViewMarginRight;

    private int mDividerLineType;
    private Color mDividerLineColor;
    private int mDividerLineHeight;


    private int mLeftTextViewLineSpacingExtra;
    private int mCenterTextViewLineSpacingExtra;
    private int mRightTextViewLineSpacingExtra;

    /**
     * 分割线的类型
     */
    private static final int NONE = 0;
    private static final int TOP = 1;
    private static final int BOTTOM = 2;
    private static final int BOTH = 3;
    private static final int DEFAULT = BOTTOM;

    /**
     * 是否使用点击出现波纹效果
     */
//    private boolean mIsUseRipple;

    private boolean mSetSingleLine = true;
    private int mSetMaxEms = 10;
    private int mSetLines = 1;

    /**
     * TextView的Gravity
     */
    private static final int GRAVITY_LEFT_CENTER = 0;
    private static final int GRAVITY_CENTER = 1;
    private static final int GRAVITY_RIGHT_CENTER = 2;

    private static final int DEFAULT_GRAVITY = GRAVITY_CENTER;

    private int mLeftTextViewGravity;
    private int mCenterTextViewGravity;
    private int mRightTextViewGravity;

    private OfText mLeftTextView, mCenterTextView, mRightTextView;
    private OfText mLeftTopTextView, mCenterTopTextView, mRightTopTextView;
    private OfText mLeftBottomTextView, mCenterBottomTextView, mRightBottomTextView;

    private Image mLeftImageView;
    //    private ImageView rightImageView;
    private Component mTopLineView, mBottomLineView;
    private Component mCenterBaseLineView;

    private boolean mLeftViewIsClickable;
    private boolean mCenterViewIsClickable;
    private boolean mRightViewIsClickable;

    private LayoutConfig mLeftTVParams, mCenterTVParams, mRightTVParams, mTopLineParams, mBottomLineParams;
    private LayoutConfig mLeftTopTVParams, mCenterTopTVParams, mRightTopTVParams;
    private LayoutConfig mLeftBottomTVParams, mCenterBottomTVParams, mRightBottomTVParams;
    private LayoutConfig mCenterBaseLineParams;

    private OnCommonTextViewClickListener mOnCommonTextViewClickListener;

    private Element mBackground_Element;
    private boolean mIsCenterAlignLeft;
    private int mCenterViewMarginLeft;


    public CommonTextView(Context context) {
        this(context, null);
    }

    public CommonTextView(Context context, AttrSet attrSet) {
        this(context, attrSet, null);
    }

    public CommonTextView(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
    }

    private void initAttrs(Context context, AttrSet attrs) {
        mContext = context;
        mDefaultTextColor = AttrValue.get(attrs, "stv_color_common_text", new Color(0xFF373737));
        mDefaultTextSize = AttrValue.getDimension(attrs, "stv_text_size", AttrHelper.fp2px(15, context));
        mDefaultPadding = AttrValue.getDimension(attrs, "stv_margin", AttrHelper.vp2px(10, context));
        mCenterSpaceHeight = AttrHelper.vp2px(5, context);
        getAttr(attrs);
        init();
    }

    private void init() {
        initCommonTextView();
        initLineView();
        initCenterBaseLine();
        if (mLeft_IV_Element != null) {
            initLeftImageView();
        }
//        if (mRight_IV_Element!=null){
//            initRightImageView();
//        }
        if (mLeftTextString != null || mLeft_ElementLeft != null || mLeft_ElementRight != null) {
            initLeftText();
        }
        if (mCenterTextString != null) {
            initCenterText();
        }
        if (mRightTextString != null || mRight_ElementLeft != null || mRight_ElementRight != null) {
            initRightText();
        }

        if (mLeftTopTextString != null) {
            initLeftTopText();
        }
        if (mLeftBottomTextString != null) {
            initLeftBottomText();
        }

        if (mCenterTopTextString != null) {
            initCenterTopText();
        }
        if (mCenterBottomTextString != null) {
            initCenterBottomText();
        }
        if (mRightTopTextString != null) {
            initRightTopText();
        }
        if (mRightBottomTextString != null) {
            initRightBottomText();
        }
    }


    /**
     * 初始化textView
     *
     * @param textView 对象
     * @param layoutParams 对象
     * @param id id
     * @param textColor 颜色值
     * @param textSize 字体大小
     * @return 返回
     */
    public OfText initText(OfText textView, LayoutConfig layoutParams, int id, Color textColor, int textSize) {
        if (textView == null) {
            textView = new OfText(mContext);
            textView.setId(id);
            textView.setLayoutConfig(layoutParams);
            textView.setTextColor(textColor);
            textView.setTextSize(textSize, Text.TextSizeType.PX);
            textView.setLines(mSetLines);
            textView.setMultipleLine(!mSetSingleLine);
            textView.setMaxLength(mSetMaxEms);
            addComponent(textView);
        }
        return textView;
    }

    private void setTextViewGravity(OfText textView, int gravity_type) {
        switch (gravity_type) {
            case GRAVITY_LEFT_CENTER:
                textView.setTextAlignment(TextAlignment.LEFT | TextAlignment.VERTICAL_CENTER);
                break;
            case GRAVITY_CENTER:
                textView.setTextAlignment(TextAlignment.CENTER);
                break;
            case GRAVITY_RIGHT_CENTER:
                textView.setTextAlignment(TextAlignment.RIGHT | TextAlignment.VERTICAL_CENTER);
                break;
            default:
                break;
        }
    }

    /**
     * 初始化左边textView
     */
    private void initLeftText() {
        if (mLeftTextView == null) {
            if (mLeftTVParams == null) {
                mLeftTVParams = getParams(mLeftTVParams);
            }
            mLeftTVParams.addRule(VERTICAL_CENTER, TRUE);
            mLeftTVParams.addRule(RIGHT_OF, ResourceTable.Id_cLeftImageViewId);
            mLeftTVParams.setMargins(mLeftViewPaddingLeft, 0, mLeftViewPaddingRight, 0);
            mLeftTextView = initText(mLeftTextView, mLeftTVParams, ResourceTable.Id_cLeftTextId, mLeftTextColor, mLeftTextSize);
            mLeftTextView.setText(mLeftTextString);
            mLeftTextView.setLineSpacing(mLeftTextViewLineSpacingExtra, 1.0f);
            setTextViewGravity(mLeftTextView, mLeftTextViewGravity);
            if (mLeftViewIsClickable) {
                mLeftTextView.setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        if (mOnCommonTextViewClickListener != null) {
                            mOnCommonTextViewClickListener.onLeftViewClick();
                        }
                    }
                });
            }
        }
        setElement(mLeftTextView, mLeft_ElementLeft, mLeft_ElementTop, mLeft_ElementRight, mLeft_ElementBottom, mLeftIconElementPadding);

    }

    /**
     * 初始化左上textView
     */
    private void initLeftTopText() {
        if (mLeftTopTextView == null) {
            if (mLeftTopTVParams == null) {
                mLeftTopTVParams = getParams(mLeftTopTVParams);
            }
            mLeftTopTVParams.addRule(VERTICAL_CENTER, TRUE);
            mLeftTopTVParams.addRule(ABOVE, ResourceTable.Id_cCenterBaseLineId);
            mLeftTopTVParams.addRule(RIGHT_OF, ResourceTable.Id_cLeftImageViewId);
            mLeftTopTVParams.setMargins(mLeftViewPaddingLeft, 0, mLeftViewPaddingRight, 0);
            mLeftTopTextView = initText(mLeftTopTextView, mLeftTopTVParams, ResourceTable.Id_cLeftTopTextId, mLeftTopTextColor, mLeftTopTextSize);
            mLeftTopTextView.setText(mLeftTopTextString);
            setTextViewGravity(mLeftTopTextView, mLeftTextViewGravity);

        }

    }

    /**
     * 初始化左下textView
     */
    private void initLeftBottomText() {
        if (mLeftBottomTextView == null) {
            if (mLeftBottomTVParams == null) {
                mLeftBottomTVParams = getParams(mLeftBottomTVParams);
            }
            mLeftBottomTVParams.addRule(VERTICAL_CENTER, TRUE);
            mLeftBottomTVParams.addRule(BELOW, ResourceTable.Id_cCenterBaseLineId);
            mLeftBottomTVParams.addRule(RIGHT_OF, ResourceTable.Id_cLeftImageViewId);
            mLeftBottomTVParams.setMargins(mLeftViewPaddingLeft, 0, mLeftViewPaddingRight, 0);
            mLeftBottomTextView = initText(mLeftBottomTextView, mLeftBottomTVParams, ResourceTable.Id_cLeftBottomTextId, mLeftBottomTextColor, mLeftBottomTextSize);
            mLeftBottomTextView.setText(mLeftBottomTextString);
            setTextViewGravity(mLeftBottomTextView, mLeftTextViewGravity);

        }

    }

    /**
     * 初始化中间textView
     */
    private void initCenterText() {
        if (mCenterTextView == null) {
            if (mCenterTVParams == null) {
                if (mIsCenterAlignLeft) {
                    mCenterTVParams = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_CONTENT);
                } else {
                    mCenterTVParams = getParams(mCenterTVParams);
                }
            }

            mCenterTVParams.addRule(VERTICAL_CENTER, TRUE);
            mCenterTVParams.addRule(CENTER_IN_PARENT, TRUE);

            if (mIsCenterAlignLeft) {
                mCenterTextView = initText(mCenterTextView, mCenterTVParams, ResourceTable.Id_cCenterTextId, mCenterTextColor, mCenterTextSize);
                mCenterTVParams.setMargins(mCenterViewMarginLeft, 0, mCenterViewPaddingRight, 0);
                setTextViewGravity(mCenterTextView, GRAVITY_LEFT_CENTER);
            } else {
                mCenterTextView = initText(mCenterTextView, mCenterTVParams, ResourceTable.Id_cCenterTextId, mCenterTextColor, mCenterTextSize);
                mCenterTVParams.setMargins(mCenterViewPaddingLeft, 0, mCenterViewPaddingRight, 0);
                setTextViewGravity(mCenterTextView, mCenterTextViewGravity);
            }

            mCenterTextView.setText(mCenterTextString);
            mCenterTextView.setLineSpacing(mCenterTextViewLineSpacingExtra, 1.0f);

            if (mCenterViewIsClickable) {
                mCenterTextView.setClickedListener(new ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        if (mOnCommonTextViewClickListener != null) {
                            mOnCommonTextViewClickListener.onCenterViewClick();
                        }
                    }
                });
            }
        }
        setElement(mCenterTextView, mCenter_ElementLeft, mCenter_ElementTop, mCenter_ElementRight, mCenter_ElementBottom, mCenterIconElementPadding);
    }

    /**
     * 初始化中上textView
     */
    private void initCenterTopText() {
        if (mCenterTopTextView == null) {
            if (mCenterTopTVParams == null) {
                mCenterTopTVParams = getParams(mCenterTopTVParams);
            }
            mCenterTopTVParams.addRule(VERTICAL_CENTER, TRUE);
            mCenterTopTVParams.addRule(CENTER_IN_PARENT, TRUE);
            mCenterTopTVParams.addRule(ABOVE, ResourceTable.Id_cCenterBaseLineId);
            mCenterTopTVParams.setMargins(mCenterViewPaddingLeft, 0, mCenterViewPaddingRight, 0);
            mCenterTopTextView = initText(mCenterTopTextView, mCenterTopTVParams, ResourceTable.Id_cCenterTopTextId, mCenterTopTextColor, mCenterTopTextSize);
            mCenterTopTextView.setText(mCenterTopTextString);
            mCenterTopTextView.setLineSpacing(mCenterTextViewLineSpacingExtra, 1.0f);
            setTextViewGravity(mCenterTopTextView, mCenterTextViewGravity);
        }
    }

    /**
     * 初始化中下textView
     */
    private void initCenterBottomText() {
        if (mCenterBottomTextView == null) {
            if (mCenterBottomTVParams == null) {
                mCenterBottomTVParams = getParams(mCenterBottomTVParams);
            }
            mCenterBottomTVParams.addRule(VERTICAL_CENTER, TRUE);
            mCenterBottomTVParams.addRule(CENTER_IN_PARENT, TRUE);
            mCenterBottomTVParams.addRule(BELOW, ResourceTable.Id_cCenterBaseLineId);
            mCenterBottomTVParams.setMargins(mCenterViewPaddingLeft, 0, mCenterViewPaddingRight, 0);
            mCenterBottomTextView = initText(mCenterBottomTextView, mCenterBottomTVParams, ResourceTable.Id_cCenterBottomTextId, mCenterBottomTextColor, mCenterBottomTextSize);
            mCenterBottomTextView.setText(mCenterBottomTextString);
            mCenterBottomTextView.setLineSpacing(mCenterTextViewLineSpacingExtra, 1.0f);
            setTextViewGravity(mCenterBottomTextView, mCenterTextViewGravity);
        }

    }


    /**
     * 初始化右边textView
     */
    private void initRightText() {
        if (mRightTextView == null) {
            if (mRightTVParams == null) {
                mRightTVParams = getParams(mRightTVParams);
            }
            mRightTVParams.addRule(VERTICAL_CENTER, TRUE);
            mRightTVParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
            mRightTVParams.addRule(LEFT_OF, ResourceTable.Id_cRightImageViewId);
            mRightTVParams.setMargins(mRightViewPaddingLeft, 0, mRightViewPaddingRight, 0);
            mRightTextView = initText(mRightTextView, mRightTVParams, ResourceTable.Id_cRightTextId, mRightTextColor, mRightTextSize);
            mRightTextView.setText(mRightTextString);
            mRightTextView.setLineSpacing(mRightTextViewLineSpacingExtra, 1.0f);
            setTextViewGravity(mRightTextView, mRightTextViewGravity);
            if (mRightViewIsClickable) {
                mRightTextView.setClickedListener(v -> {
                    if (mOnCommonTextViewClickListener != null) {
                        mOnCommonTextViewClickListener.onRightViewClick();
                    }
                });
            }

        }
        setElement(mRightTextView, mRight_ElementLeft, mRight_ElementTop, mRight_ElementRight, mRight_ElementBottom, mRightIconElementPadding);
    }

    /**
     * 设置textView的Element
     *
     * @param textView 对象
     * @param ElementLeft 左边图标
     * @param ElementTop 上边图标
     * @param ElementRight 右边图标
     * @param ElementBottom 下边图标
     * @param ElementPadding 图标距离文字的间距
     */
    public void setElement(OfText textView, Element ElementLeft, Element ElementTop, Element ElementRight, Element ElementBottom, int ElementPadding) {
        // todo 待支持该方法
        //textView.setCompoundElementsWithIntrinsicBounds(ElementLeft, ElementTop, ElementRight, ElementBottom);
        //textView.setCompoundElementPadding(ElementPadding);
    }


    /**
     * 初始化右上textView
     */
    private void initRightTopText() {
        if (mRightTopTextView == null) {
            if (mRightTopTVParams == null) {
                mRightTopTVParams = getParams(mRightTopTVParams);
            }
            mRightTopTVParams.addRule(VERTICAL_CENTER, TRUE);
            mRightTopTVParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
            mRightTopTVParams.addRule(ABOVE, ResourceTable.Id_cCenterBaseLineId);
            mRightTopTVParams.addRule(LEFT_OF, ResourceTable.Id_cRightImageViewId);
            mRightTopTVParams.setMargins(mRightViewPaddingLeft, 0, mRightViewPaddingRight, 0);
            mRightTopTextView = initText(mRightTopTextView, mRightTopTVParams, ResourceTable.Id_cRightTopTextId, mRightTopTextColor, mRightTopTextSize);
            mRightTopTextView.setText(mRightTopTextString);
            mRightTopTextView.setLineSpacing(mRightTextViewLineSpacingExtra, 1.0f);
            setTextViewGravity(mRightTopTextView, mRightTextViewGravity);
        }
    }

    /**
     * 初始化右下textView
     */
    private void initRightBottomText() {
        if (mRightBottomTextView == null) {
            if (mRightBottomTVParams == null) {
                mRightBottomTVParams = getParams(mRightBottomTVParams);
            }
            mRightBottomTVParams.addRule(VERTICAL_CENTER, TRUE);
            mRightBottomTVParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
            mRightBottomTVParams.addRule(BELOW, ResourceTable.Id_cCenterBaseLineId);
            mRightBottomTVParams.addRule(LEFT_OF, ResourceTable.Id_cRightImageViewId);
            mRightBottomTVParams.setMargins(mRightViewPaddingLeft, 0, mRightViewPaddingRight, 0);
            mRightBottomTextView = initText(mRightBottomTextView, mRightBottomTVParams, ResourceTable.Id_cRightBottomTextId, mRightBottomTextColor, mRightBottomTextSize);
            mRightBottomTextView.setText(mRightBottomTextString);
            mRightBottomTextView.setLineSpacing(mRightTextViewLineSpacingExtra, 1.0f);
            setTextViewGravity(mRightBottomTextView, mRightTextViewGravity);
        }
    }


    /**
     * 初始化Params
     *
     * @param params 对象
     * @return 返回
     */
    public LayoutConfig getParams(LayoutConfig params) {
        if (params == null) {
            params = new LayoutConfig(LayoutConfig.MATCH_CONTENT, LayoutConfig.MATCH_CONTENT);
        }
        return params;
    }


    /**
     * 为了设置上下两排文字居中对齐显示而需要设置的基准线
     */
    private void initCenterBaseLine() {
        if (mCenterBaseLineView == null) {
            if (mCenterBaseLineParams == null) {
                mCenterBaseLineParams = new LayoutConfig(LayoutConfig.MATCH_PARENT, mCenterSpaceHeight);
                mCenterBaseLineParams.addRule(VERTICAL_CENTER, TRUE);
            }
            mCenterBaseLineView = new Component(mContext);

            mCenterBaseLineView.setId(ResourceTable.Id_cCenterBaseLineId);
            mCenterBaseLineView.setLayoutConfig(mCenterBaseLineParams);
        }
        addComponent(mCenterBaseLineView);
    }

    /**
     * 初始化左边ImageView
     * 主要是为了便于使用第三方图片框架获取网络图片使用
     */
    private void initLeftImageView() {
        mLeftImageView = new Image(mContext);
        LayoutConfig leftIVParams = new LayoutConfig(LayoutConfig.MATCH_CONTENT, LayoutConfig.MATCH_CONTENT);
        leftIVParams.addRule(ALIGN_PARENT_LEFT, TRUE);
        leftIVParams.addRule(DependentLayout.LayoutConfig.VERTICAL_CENTER, TRUE);
        leftIVParams.setMargins(mLeftImageViewMarginLeft, 0, 0, 0);
        mLeftImageView.setScaleMode(Image.ScaleMode.CENTER);
        mLeftImageView.setId(ResourceTable.Id_cLeftImageViewId);
        mLeftImageView.setLayoutConfig(leftIVParams);
        if (mLeft_IV_Element != null) {
            mLeftImageView.setImageElement(mLeft_IV_Element);
        }
        addComponent(mLeftImageView);
    }


    /**
     * 初始化分割线
     */
    private void initLineView() {
        switch (mDividerLineType) {
            case NONE:
                break;
            case TOP:
                setTopLineMargin();
                break;
            case BOTTOM:
                setBottomLineMargin();
                break;
            case BOTH:
                setTopLineMargin();
                setBottomLineMargin();
                break;
            default:
                break;
        }
    }

    /**
     * 设置顶部的分割线
     */
    private void setTopLineMargin() {
        if (mTopDividerLineMarginLR != 0) {
            initTopLineView(mTopDividerLineMarginLR, mTopDividerLineMarginLR);
        } else if (mBothDividerLineMarginLeft != 0 | mBothDividerLineMarginRight != 0) {
            initTopLineView(mBothDividerLineMarginLeft, mBothDividerLineMarginRight);
        } else {
            initTopLineView(mTopDividerLineMarginLeft, mTopDividerLineMarginRight);
        }
    }

    /**
     * 设置底部的分割线
     */
    private void setBottomLineMargin() {
        if (mBottomDividerLineMarginLR != 0) {
            initBottomLineView(mBottomDividerLineMarginLR, mBottomDividerLineMarginLR);
        } else if (mBothDividerLineMarginRight != 0 | mBothDividerLineMarginRight != 0) {
            initBottomLineView(mBothDividerLineMarginLeft, mBothDividerLineMarginRight);
        } else {
            initBottomLineView(mBottomDividerLineMarginLeft, mBottomDividerLineMarginRight);
        }
    }

    /**
     * 设置上边分割线view
     *
     * @param marginStart 起始的间距
     * @param marginEnd 结束的间距
     */
    private void initTopLineView(int marginStart, int marginEnd) {
        if (mTopLineView == null) {
            if (mTopLineParams == null) {
                mTopLineParams = new LayoutConfig(LayoutConfig.MATCH_PARENT, mDividerLineHeight);
            }
            mTopLineParams.addRule(ALIGN_PARENT_TOP, TRUE);
            mTopLineParams.setMarginLeft(marginStart);
            mTopLineParams.setMarginRight(marginEnd);
            mTopLineView = new Component(mContext);
            mTopLineView.setLayoutConfig(mTopLineParams);
            mTopLineView.setBackground(ColorUtils.getColorShapeElement(mDividerLineColor));
        }
        addComponent(mTopLineView);
    }

    /**
     * 设置底部分割线view
     *
     * @param marginStart 起始的间距
     * @param marginEnd 结束的间距
     */
    private void initBottomLineView(int marginStart, int marginEnd) {
        if (mBottomLineView == null) {
            if (mBottomLineParams == null) {
                mBottomLineParams = new LayoutConfig(LayoutConfig.MATCH_PARENT, mDividerLineHeight);
            }
            mBottomLineParams.addRule(ALIGN_PARENT_BOTTOM, TRUE);
            mBottomLineParams.setMarginLeft(marginStart);
            mBottomLineParams.setMarginRight(marginEnd);
            mBottomLineView = new Component(mContext);
            mBottomLineView.setLayoutConfig(mBottomLineParams);
            mBottomLineView.setBackground(ColorUtils.getColorShapeElement(mDividerLineColor));
        }
        addComponent(mBottomLineView);
    }

    private void initCommonTextView() {
        setBackground(ColorUtils.getColorShapeElement(mBackgroundColor.getValue()));
     /*   if (mIsUseRipple) {
        }*/
        setClickedListener(new ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (mOnCommonTextViewClickListener != null) {
                    mOnCommonTextViewClickListener.onCommonTextViewClick();
                }
            }
        });
        if (mBackground_Element != null) {
            setBackground(mBackground_Element);
        }
    }

    private void getAttr(AttrSet attrs) {
        Element emptyElement = null;
        ////////设置文字或者图片资源////////
        mLeft_ElementLeft = AttrValue.get(attrs, "cLeftIconResForElementLeft", emptyElement);
        mLeft_ElementTop = AttrValue.get(attrs, "cLeftIconResForElementTop", emptyElement);
        mLeft_ElementRight = AttrValue.get(attrs, "cLeftIconResForElementRight", emptyElement);
        mLeft_ElementBottom = AttrValue.get(attrs, "cLeftIconResForElementBottom", emptyElement);

        mCenter_ElementLeft = AttrValue.get(attrs, "cCenterIconResForElementLeft", emptyElement);
        mCenter_ElementTop = AttrValue.get(attrs, "cCenterIconResForElementTop", emptyElement);
        mCenter_ElementRight = AttrValue.get(attrs, "cCenterIconResForElementRight", emptyElement);
        mCenter_ElementBottom = AttrValue.get(attrs, "cCenterIconResForElementBottom", emptyElement);

        mRight_ElementLeft = AttrValue.get(attrs, "cRightIconResForElementLeft", emptyElement);
        mRight_ElementTop = AttrValue.get(attrs, "cRightIconResForElementTop", emptyElement);
        mRight_ElementRight = AttrValue.get(attrs, "cRightIconResForElementRight", emptyElement);
        mRight_ElementBottom = AttrValue.get(attrs, "cRightIconResForElementBottom", emptyElement);

        mLeft_IV_Element = AttrValue.get(attrs, "cLeftImageViewElementRes", emptyElement);
//        mRight_IV_Element = attrs.getElement("cRightImageViewElementRes);
        /////////////////////

        String emptyString = "";
        mLeftTextString = AttrValue.get(attrs, "cLeftTextString", emptyString);
        mLeftTopTextString = AttrValue.get(attrs, "cLeftTopTextString", emptyString);
        mLeftBottomTextString = AttrValue.get(attrs, "cLeftBottomTextString", emptyString);

        mCenterTextString = AttrValue.get(attrs, "cCenterTextString", emptyString);
        mCenterTopTextString = AttrValue.get(attrs, "cCenterTopTextString", emptyString);
        mCenterBottomTextString = AttrValue.get(attrs, "cCenterBottomTextString", emptyString);

        mRightTextString = AttrValue.get(attrs, "cRightTextString", emptyString);
        mRightTopTextString = AttrValue.get(attrs, "cRightTopTextString", emptyString);
        mRightBottomTextString = AttrValue.get(attrs, "cRightBottomTextString", emptyString);

        mLeftTextColor = AttrValue.get(attrs, "cLeftTextColor", mDefaultTextColor);
        mLeftTopTextColor = AttrValue.get(attrs, "cLeftTopTextColor", mDefaultTextColor);
        mLeftBottomTextColor = AttrValue.get(attrs, "cLeftBottomTextColor", mDefaultTextColor);

        mCenterTextColor = AttrValue.get(attrs, "cCenterTextColor", mDefaultTextColor);
        mCenterTopTextColor = AttrValue.get(attrs, "cCenterTopTextColor", mDefaultTextColor);
        mCenterBottomTextColor = AttrValue.get(attrs, "cCenterBottomTextColor", mDefaultTextColor);

        mRightTextColor = AttrValue.get(attrs, "cRightTextColor", mDefaultTextColor);
        mRightTopTextColor = AttrValue.get(attrs, "cRightTopTextColor", mDefaultTextColor);
        mRightBottomTextColor = AttrValue.get(attrs, "cRightBottomTextColor", mDefaultTextColor);

        mLeftTextSize = AttrValue.getDimension(attrs, "cLeftTextSize", mDefaultTextSize);
        mLeftTopTextSize = AttrValue.getDimension(attrs, "cLeftTopTextSize", mDefaultTextSize);
        mLeftBottomTextSize = AttrValue.getDimension(attrs, "cLeftBottomTextSize", mDefaultTextSize);

        mCenterTextSize = AttrValue.getDimension(attrs, "cCenterTextSize", mDefaultTextSize);
        mCenterTopTextSize = AttrValue.getDimension(attrs, "cCenterTopTextSize", mDefaultTextSize);
        mCenterBottomTextSize = AttrValue.getDimension(attrs, "cCenterBottomTextSize", mDefaultTextSize);

        mRightTextSize = AttrValue.getDimension(attrs, "cRightTextSize", mDefaultTextSize);
        mRightTopTextSize = AttrValue.getDimension(attrs, "cRightTopTextSize", mDefaultTextSize);
        mRightBottomTextSize = AttrValue.getDimension(attrs, "cRightBottomTextSize", mDefaultTextSize);

        int defPadding = 0;

        mLeftIconElementPadding = AttrValue.getDimension(attrs, "cLeftIconElementPadding, mDefaultPadding", defPadding);
        mCenterIconElementPadding = AttrValue.getDimension(attrs, "cCenterIconElementPadding, mDefaultPadding", defPadding);
        mRightIconElementPadding = AttrValue.getDimension(attrs, "cRightIconElementPadding, mDefaultPadding", defPadding);

        mLeftViewPaddingLeft = AttrValue.getDimension(attrs, "cLeftViewPaddingLeft, mDefaultPadding", defPadding);
        mLeftViewPaddingRight = AttrValue.getDimension(attrs, "cLeftViewPaddingRight, mDefaultPadding", defPadding);
        mCenterViewPaddingLeft = AttrValue.getDimension(attrs, "cCenterViewPaddingLeft, mDefaultPadding", defPadding);
        mCenterViewPaddingRight = AttrValue.getDimension(attrs, "cCenterViewPaddingRight, mDefaultPadding", defPadding);
        mRightViewPaddingLeft = AttrValue.getDimension(attrs, "cRightViewPaddingLeft, mDefaultPadding", defPadding);
        mRightViewPaddingRight = AttrValue.getDimension(attrs, "cRightViewPaddingRight, mDefaultPadding", defPadding);

        mBothDividerLineMarginLeft = AttrValue.getDimension(attrs, "cBothDividerLineMarginLeft, 0", defPadding);
        mBothDividerLineMarginRight = AttrValue.getDimension(attrs, "cBothDividerLineMarginRight, 0", defPadding);

        mTopDividerLineMarginLR = AttrValue.getDimension(attrs, "cTopDividerLineMarginLR", 0);
        mTopDividerLineMarginLeft = AttrValue.getDimension(attrs, "cTopDividerLineMarginLeft", 0);
        mTopDividerLineMarginRight = AttrValue.getDimension(attrs, "cTopDividerLineMarginRight", 0);

        mBottomDividerLineMarginLR = AttrValue.getDimension(attrs, "cBottomDividerLineMarginLR", 0);
        mBottomDividerLineMarginLeft = AttrValue.getDimension(attrs, "cBottomDividerLineMarginLeft", 0);
        mBottomDividerLineMarginRight = AttrValue.getDimension(attrs, "cBottomDividerLineMarginRight", 0);

        mLeftImageViewMarginLeft = AttrValue.getDimension(attrs, "cLeftImageViewMarginLeft", mDefaultPadding);
//        mRightImageViewMarginRight = AttrValue.getDimension(attrs,"cRightImageViewMarginRight, mDefaultPadding);

        mCenterSpaceHeight = AttrValue.getDimension(attrs, "cCenterSpaceHeight", mCenterSpaceHeight);

        mLeftTextViewLineSpacingExtra = AttrValue.getDimension(attrs, "cLeftTextViewLineSpacingExtra", 0);
        mCenterTextViewLineSpacingExtra = AttrValue.getDimension(attrs, "cCenterTextViewLineSpacingExtra", 0);
        mRightTextViewLineSpacingExtra = AttrValue.getDimension(attrs, "cRightTextViewLineSpacingExtra", 0);

        mDividerLineType = AttrValue.get(attrs, "cShowDividerLineType", DEFAULT);
        Color xui_config_color_separator_light = Color.TRANSPARENT;
        mDividerLineColor = AttrValue.get(attrs, "cDividerLineColor", xui_config_color_separator_light);

        mDividerLineHeight = AttrValue.getDimension(attrs, "cDividerLineHeight", dip2px(mContext, 0.5f));

//        mIsUseRipple = AttrValue.get(attrs, "cUseRipple", false);

        mBackgroundColor = AttrValue.get(attrs, "cBackgroundColor", mBackgroundColor);

        mSetSingleLine = AttrValue.get(attrs, "cSetSingleLine", true);
        mSetMaxEms = AttrValue.get(attrs, "cSetMaxEms", mSetMaxEms);
        mSetLines = AttrValue.get(attrs, "cSetLines", 1);

        mLeftTextViewGravity = AttrValue.get(attrs, "cLeftTextViewGravity", DEFAULT_GRAVITY);
        mCenterTextViewGravity = AttrValue.get(attrs, "cCenterTextViewGravity", DEFAULT_GRAVITY);
        mRightTextViewGravity = AttrValue.get(attrs, "cRightTextViewGravity", DEFAULT_GRAVITY);

        mLeftViewIsClickable = AttrValue.get(attrs, "cLeftViewIsClickable", false);
        mCenterViewIsClickable = AttrValue.get(attrs, "cCenterViewIsClickable", false);
        mRightViewIsClickable = AttrValue.get(attrs, "cRightViewIsClickable", false);

        mBackground_Element = AttrValue.get(attrs, "cBackgroundElementRes", emptyElement);

        mIsCenterAlignLeft = AttrValue.get(attrs, "cIsCenterAlignLeft", false);
        mCenterViewMarginLeft = AttrValue.getDimension(attrs, "cCenterViewMarginLeft", dip2px(mContext, 200));
    }

    /**
     * 设置左边文字字符串
     *
     * @param string 字符串
     * @return 返回
     */
    public CommonTextView setLeftTextString(String string) {
        if (mLeftTextView == null) {
            initLeftText();
        }
        mLeftTextView.setText(string);
        return this;
    }

    /**
     * 设置左上文字字符串
     *
     * @param string 字符串
     * @return 返回
     */
    public CommonTextView setLeftTopTextString(String string) {
        if (mLeftTopTextView == null) {
            initLeftTopText();
        }
        mLeftTopTextView.setText(string);
        return this;
    }

    /**
     * 设置左下文字字符串
     *
     * @param string 字符串
     * @return 返回
     */
    public CommonTextView setLeftBottomTextString(String string) {
        if (mLeftBottomTextView == null) {
            initLeftBottomText();
        }
        mLeftBottomTextView.setText(string);
        return this;
    }

    /**
     * 设置左边文字字体大小
     *
     * @param size 字体大小
     * @return 返回
     */
    public CommonTextView setLeftTextSize(int size) {
        if (mLeftTextView == null) {
            initLeftText();
        }
        mLeftTextView.setTextSize(size);
        return this;
    }

    /**
     * set Left TextColor
     *
     * @param color textColor
     * @return return
     */
    public CommonTextView setLeftTextColor(int color) {
        if (mLeftTextView == null) {
            initLeftText();
        }
        mLeftTextView.setTextColor(new Color(color));
        return this;
    }

    /**
     * 设置中间文字字符串
     *
     * @param string 字符串
     * @return 返回
     */
    public CommonTextView setCenterTextString(String string) {
        if (mCenterTextView == null) {
            initCenterText();
        }
        mCenterTextView.setText(string);
        return this;
    }

    /**
     * 设置中上文字字符串
     *
     * @param string 字符串
     * @return 返回
     */
    public CommonTextView setCenterTopTextString(String string) {
        if (mCenterTopTextView == null) {
            initCenterTopText();
        }
        mCenterTopTextView.setText(string);
        return this;
    }

    /**
     * 设置中下文字字符串
     *
     * @param string 字符串
     * @return 返回
     */
    public CommonTextView setCenterBottomTextString(String string) {
        if (mCenterBottomTextView == null) {
            initCenterBottomText();
        }
        mCenterBottomTextView.setText(string);
        return this;
    }

    /**
     * 设置中间文字字体大小
     *
     * @param size 字体大小
     * @return 返回
     */
    public CommonTextView setCenterTextSize(int size) {
        if (mCenterTextView == null) {
            initCenterText();
        }
        mCenterTextView.setTextSize(size);
        return this;
    }

    /**
     * 设置中间文字颜色值
     *
     * @param color 颜色值
     * @return 返回
     */
    public CommonTextView setCenterTextColor(int color) {
        if (mCenterTextView == null) {
            initCenterText();
        }
        mCenterTextView.setTextColor(new Color(color));
        return this;
    }

    /**
     * 设置右边文字字符串
     *
     * @param string 字符串
     * @return 返回
     */
    public CommonTextView setRightTextString(String string) {
        if (mRightTextView == null) {
            initRightText();
        }
        mRightTextView.setText(string);
        return this;
    }

    /**
     * 设置右上文字字符串
     *
     * @param string 字符串
     * @return 返回
     */
    public CommonTextView setRightTopTextString(String string) {
        if (mRightTopTextView == null) {
            initRightTopText();
        }
        mRightTopTextView.setText(string);
        return this;
    }

    /**
     * 设置右下文字字符串
     *
     * @param string 字符串
     * @return 返回
     */
    public CommonTextView setRightBottomTextString(String string) {
        if (mRightBottomTextView == null) {
            initRightBottomText();
        }
        mRightBottomTextView.setText(string);
        return this;
    }

    /**
     * 设置右边文字的字体大小
     *
     * @param size 字体大小
     * @return 返回
     */
    public CommonTextView setRightTextSize(int size) {
        if (mRightTextView == null) {
            initRightText();
        }
        mRightTextView.setTextSize(size);
        return this;
    }

    /**
     * 设置右边文字的颜色
     *
     * @param color 颜色值
     * @return 返回
     */
    public CommonTextView setRightTextColor(int color) {
        if (mRightTextView == null) {
            initRightText();
        }
        mRightTextView.setTextColor(color);
        return this;
    }

    /**
     * 设置左边view的ElementLeft
     *
     * @param ElementLeft 资源
     * @return 返回
     */
    public CommonTextView setLeftElementLeft(Element ElementLeft) {
        if (ElementLeft != null) {
            ElementLeft.setBounds(0, 0, ElementLeft.getMinWidth(), ElementLeft.getMinHeight());
        }
        if (mLeftTextView == null) {
            initLeftText();
        }
        mLeftTextView.setCompoundElements(ElementLeft, null, null, null);
        return this;
    }

    /**
     * 设置左边view的ElementTop
     *
     * @param ElementTop 资源
     * @return Top 返回
     */
    public CommonTextView setLeftElementTop(Element ElementTop) {
        if (ElementTop != null) {
            ElementTop.setBounds(0, 0, ElementTop.getMinWidth(), ElementTop.getMinHeight());
        }
        if (mLeftTextView == null) {
            initLeftText();
        }
        mLeftTextView.setCompoundElements(null, ElementTop, null, null);
        return this;
    }

    /**
     * 设置左边view的ElementRight
     *
     * @param ElementRight 资源
     * @return 返回
     */
    public CommonTextView setLeftElementRight(Element ElementRight) {
        if (ElementRight != null) {
            ElementRight.setBounds(0, 0, ElementRight.getMinWidth(), ElementRight.getMinHeight());
        }
        if (mLeftTextView == null) {
            initLeftText();
        }
        mLeftTextView.setCompoundElements(null, null, ElementRight, null);
        return this;
    }

    /**
     * 设置左边view的ElementBottom
     *
     * @param ElementBottom 资源
     * @return 返回
     */
    public CommonTextView setLeftElementBottom(Element ElementBottom) {
        if (ElementBottom != null) {
            ElementBottom.setBounds(0, 0, ElementBottom.getMinWidth(), ElementBottom.getMinHeight());
        }
        if (mLeftTextView == null) {
            initLeftText();
        }
        mLeftTextView.setCompoundElements(null, null, null, ElementBottom);
        return this;
    }

    /**
     * 设置中间view的ElementLeft
     *
     * @param ElementLeft 资源
     * @return 返回
     */
    public CommonTextView setCenterElementLeft(Element ElementLeft) {
        if (ElementLeft != null) {
            ElementLeft.setBounds(0, 0, ElementLeft.getMinWidth(), ElementLeft.getMinHeight());
        }
        if (mCenterTextView == null) {
            initCenterText();
        }
        mCenterTextView.setCompoundElements(ElementLeft, null, null, null);
        return this;
    }

    /**
     * 设置中间view的ElementTop
     *
     * @param ElementTop 资源
     * @return Top 返回
     */
    public CommonTextView setCenterElementTop(Element ElementTop) {
        if (ElementTop != null) {
            ElementTop.setBounds(0, 0, ElementTop.getMinWidth(), ElementTop.getMinHeight());
        }
        if (mCenterTextView == null) {
            initCenterText();
        }
        mCenterTextView.setCompoundElements(null, ElementTop, null, null);
        return this;
    }

    /**
     * 设置中间view的ElementRight
     *
     * @param ElementRight 资源
     * @return 返回
     */
    public CommonTextView setCenterElementRight(Element ElementRight) {
        if (ElementRight != null) {
            ElementRight.setBounds(0, 0, ElementRight.getMinWidth(), ElementRight.getMinHeight());
        }
        if (mCenterTextView == null) {
            initCenterText();
        }
        mCenterTextView.setCompoundElements(null, null, ElementRight, null);
        return this;
    }

    /**
     * 设置中间view的ElementBottom
     *
     * @param ElementBottom 资源
     * @return 返回
     */
    public CommonTextView setCenterElementBottom(Element ElementBottom) {
        if (ElementBottom != null) {
            ElementBottom.setBounds(0, 0, ElementBottom.getMinWidth(), ElementBottom.getMinHeight());
        }
        if (mCenterTextView == null) {
            initCenterText();
        }
        mCenterTextView.setCompoundElements(null, null, null, ElementBottom);
        return this;
    }

    /**
     * 设置右边view的ElementLeft
     *
     * @param ElementLeft 资源
     * @return 返回
     */
    public CommonTextView setRightElementLeft(Element ElementLeft) {
        if (ElementLeft != null) {
            ElementLeft.setBounds(0, 0, ElementLeft.getMinWidth(), ElementLeft.getMinHeight());
        }
        if (mRightTextView == null) {
            initRightText();
        }
        mRightTextView.setCompoundElements(ElementLeft, null, null, null);
        return this;
    }

    /**
     * 设置右边view的ElementTop
     *
     * @param ElementTop 资源
     * @return return
     */
    public CommonTextView setRightElementTop(Element ElementTop) {
        if (ElementTop != null) {
            ElementTop.setBounds(0, 0, ElementTop.getMinWidth(), ElementTop.getMinHeight());
        }
        if (mRightTextView == null) {
            initRightText();
        }
        mRightTextView.setCompoundElements(null, ElementTop, null, null);
        return this;
    }

    /**
     * 设置右边view的ElementRight
     *
     * @param ElementRight 资源
     * @return 返回
     */
    public CommonTextView setRightElementRight(Element ElementRight) {
        if (ElementRight != null) {
            ElementRight.setBounds(0, 0, ElementRight.getMinWidth(), ElementRight.getMinHeight());
        }
        if (mRightTextView == null) {
            initRightText();
        }
        mRightTextView.setCompoundElements(null, null, ElementRight, null);
        return this;
    }

    /**
     * 设置右边view的ElementBottom
     *
     * @param ElementBottom 资源
     * @return 返回
     */
    public CommonTextView setRightElementBottom(Element ElementBottom) {
        if (ElementBottom != null) {
            ElementBottom.setBounds(0, 0, ElementBottom.getMinWidth(), ElementBottom.getMinHeight());
        }
        if (mRightTextView == null) {
            initRightText();
        }
        mRightTextView.setCompoundElements(null, null, null, ElementBottom);
        return this;
    }

    /**
     * 获取左边imageView
     *
     * @return 返回imageView对象
     */
    public Image getLeftImageView() {
        if (mLeftImageView == null) {
            initLeftImageView();
        }
        return mLeftImageView;
    }

    /**
     * 获取左边textView的值
     *
     * @return 返回
     */
    public String getLeftTextString() {
        return mLeftTextView != null ? mLeftTextView.getText() : "";
    }

    /**
     * 获取左上textView的值
     *
     * @return 返回
     */
    public String getLeftTopTextString() {
        return mLeftTopTextView != null ? mLeftTopTextView.getText() : "";
    }

    /**
     * 获取左下textView的值
     *
     * @return 返回
     */
    public String getLeftBottomTextString() {
        return mLeftBottomTextView != null ? mLeftBottomTextView.getText() : "";
    }

    /**
     * 获取中间textView的值
     *
     * @return 返回
     */
    public String getCenterTextString() {
        return mCenterTextView != null ? mCenterTextView.getText() : "";
    }

    /**
     * 获取中上textView的值
     *
     * @return 返回
     */
    public String getCenterTopTextString() {
        return mCenterTopTextView != null ? mCenterTopTextView.getText() : "";
    }

    /**
     * 获取中下textView的值
     *
     * @return 返回
     */
    public String getCenterBottomTextString() {
        return mCenterBottomTextView != null ? mCenterBottomTextView.getText() : "";
    }

    /**
     * 获取右边textView的值
     *
     * @return 返回
     */
    public String getRightTextString() {
        return mRightTextView != null ? mRightTextView.getText() : "";
    }

    /**
     * 获取右上textView的值
     *
     * @return 返回
     */
    public String getRightTopTextString() {
        return mRightTopTextView != null ? mRightTopTextView.getText() : "";
    }

    /**
     * 获取右下textView的值
     *
     * @return 返回
     */
    public String getRightBottomTextString() {
        return mRightBottomTextView != null ? mRightBottomTextView.getText() : "";
    }

    @Override
    public void setTypeface(Font typeface) {
        if (mLeftTextView != null) {
            mLeftTextView.setTypeface(typeface);
        }
        if (mCenterTextView != null) {
            mCenterTextView.setTypeface(typeface);
        }
        if (mRightTextView != null) {
            mRightTextView.setTypeface(typeface);
        }
        if (mLeftTopTextView != null) {
            mLeftTopTextView.setTypeface(typeface);
        }
        if (mCenterTopTextView != null) {
            mCenterTopTextView.setTypeface(typeface);
        }
        if (mRightTopTextView != null) {
            mRightTopTextView.setTypeface(typeface);
        }
        if (mLeftBottomTextView != null) {
            mLeftBottomTextView.setTypeface(typeface);
        }
        if (mCenterBottomTextView != null) {
            mCenterBottomTextView.setTypeface(typeface);
        }
        if (mRightBottomTextView != null) {
            mRightBottomTextView.setTypeface(typeface);
        }
    }

    /**
     * 点击事件接口
     */
    public static class OnCommonTextViewClickListener {
        public void onCommonTextViewClick() {
        }

        public void onLeftViewClick() {
        }

        public void onCenterViewClick() {
        }

        public void onRightViewClick() {
        }

    }

    /**
     * 点击事件
     *
     * @param listener listener对象
     * @return 返回当前对象便于链式操作
     */
    public CommonTextView setOnCommonTextViewClickListener(OnCommonTextViewClickListener listener) {
        this.mOnCommonTextViewClickListener = listener;
        return this;
    }

    /**
     * 设置左边view可点击
     *
     * @param isClickable boolean类型
     * @return 返回
     */
    public CommonTextView setLeftViewIsClickable(boolean isClickable) {
        if (isClickable) {
            if (mLeftTextView != null) {
                mLeftTextView.setClickedListener(v -> {
                    if (mOnCommonTextViewClickListener != null) {
                        mOnCommonTextViewClickListener.onLeftViewClick();
                    }
                });
            }
        }
        return this;
    }

    /**
     * 设置中间view可点击
     *
     * @param isClickable boolean类型
     * @return 返回
     */
    public CommonTextView setCenterViewIsClickable(boolean isClickable) {
        if (isClickable) {
            if (mCenterTextView != null) {
                mCenterTextView.setClickedListener(v -> {
                    if (mOnCommonTextViewClickListener != null) {
                        mOnCommonTextViewClickListener.onCenterViewClick();
                    }
                });
            }
        }
        return this;
    }

    /**
     * 设置右边view可点击
     *
     * @param isClickable boolean类型
     * @return 返回
     */
    public CommonTextView setRightViewIsClickable(boolean isClickable) {
        if (isClickable) {
            if (mRightTextView != null) {
                mRightTextView.setClickedListener(v -> {
                    if (mOnCommonTextViewClickListener != null) {
                        mOnCommonTextViewClickListener.onRightViewClick();
                    }
                });
            }
        }
        return this;
    }

    private int dip2px(Context mContext, float v) {
        return AttrHelper.vp2px(v, mContext);
    }

    /**
     * 单位转换工具类
     *
     * @param context 上下文对象
     * @param pxValue 值
     * @return 返回值
     */
    public int px2dip(Context context, float pxValue) {
        return DisplayUtils.px2vp(context, pxValue);
    }

    /**
     * 单位转换工具类
     *
     * @param context 上下文对象
     * @param spValue 值
     * @return 返回值
     */
    public int sp2px(Context context, float spValue) {
        return AttrHelper.fp2px(spValue, mContext);
    }
}
